<template>
	<view class="content" v-if="pageshow">
		<view class="padding">
			<!-- 1=已取消,1=待付款,3=待服务,4=服务中,5=待评价,6=已完成 -->
			<view class="bigtext" v-show="orderDetail.checkinfo_type==10">待审核</view>
			<view class="bigtext" v-show="orderDetail.checkinfo_type==20">已通过</view>
			<view class="bigtext" v-show="orderDetail.checkinfo_type==30">已拒绝</view>
			<view class="bigtext" v-show="orderDetail.checkinfo_type==40">已取消</view>
			<!-- 商家信息 -->
			<!-- <view class="padding ffffff border_2 margin_top">
				<view class="flexbetween">
					<view class="flexleft">
						<view class="imgBox margin_right2">
							<image :src="orderDetail.user.avatar" mode=""></image>
						</view>
						<view class="color_ling text_six">{{orderDetail.user.nickname}}</view>
					</view>
				</view>
			</view> -->
			<!-- 商品 -->
			<view class="ffffff padding border_2 margin_top">
				<view class="text_x color_ling">订单商品</view>
				<view class="margin_top">
					<view class="flexbetween">
						<view class="shilitu">
							<image :src="orderDetail.order.service_image_text" mode=""></image>
						</view>
						<view class="" style="width: 74%;">
							<view class="ershib yhxiank">{{orderDetail.order.service_name}}</view>
							<view class="flexbetween margin_top6">
								<view class="qianshu">¥{{orderDetail.refund_money}}</view>
								<view class="shuliang">X1</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 商品详情 -->
			<view class="paddingbom">
				<view class="ffffff padding border_2 margin_top">
					<view class="flexbetween">
						<view class="tuihuo">实际退款金额</view>
						<view class="text_x" style="color:rgba(243, 39, 28, 1);">¥{{orderDetail.real_money}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">订单编号</view>
						<view class="huisetext">{{orderDetail.refund_no}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">下单时间</view>
						<view class="huisetext">{{orderDetail.createtime_text}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">支付方式</view>
						<view class="huisetext">{{orderDetail.order.pay_type_text}}</view>
					</view>
					<view class="flexbetween margin_top" v-if="orderDetail.error_reason">
						<view class="tuihuo">拒绝理由</view>
						<view class="huisetext">{{orderDetail.error_reason}}</view>
					</view>

				</view>
			</view>
			<!-- 固定底部 -->
			<view class="gudingdb ffffff">
				<view class="flexright">
					<view class="huisebtn" v-show="orderDetail.can_refuse" @click.stop="refuseRefund(orderDetail.id)">
						拒绝退款</view>
					<view class="huangsebtn margin_left3" v-show="orderDetail.can_agree"
						@click.stop="agreeRefund(orderDetail)">同意退款</view>
				</view>
			</view>
		</view>
		<!-- 拒绝退款 -->
		<u-modal :show="modalshow" :title="title" showCancelButton confirmColor="#f12a1f"
			@cancel="modalshow=false,error_reason=''" @confirm="confirmReturn">
			<view class="slot-content">
				<input class="text" type="text" placeholder="请输入拒绝原因" v-model="error_reason" v-if="type==1">
				<input class="text" type="text" placeholder="请输入退款金额" v-model="real_money" v-if="type==2">
			</view>
		</u-modal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				orderID: '', // 订单 id
				orderDetail: {
					seller: {
						avatar: ""
					}
				}, // 订单详情内容
				pageshow: false,
				qrcodeurl: '',
				user_id: uni.getStorageSync("user_id"),
				modalshow: false,
				title: "拒绝退款",
				error_reason: "", //拒绝理由
				tkid: "",
				type: 1,
				real_money: "", //实际退款金额
			}
		},
		onLoad(options) {
			this.orderID = options.id
		},
		onShow() {
			this.getOrderInfo()
		},
		methods: {
			// 获取订单详情
			getOrderInfo() {
				let _this = this
				httpRequest.request('/api/shop.service_refund/getdetail', 'GET', {
					order_refund_id: _this.orderID
				}).then(res => {
					if (res.code == 1) {
						_this.orderDetail = res.data
						this.pageshow = true
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			refuseRefund(id) { //拒绝退款
				this.tkid = id
				this.modalshow = true
				this.title = "拒绝退款"
				this.type = 1
			},
			agreeRefund(item) { //同意退款
				this.tkid = item.id
				this.modalshow = true
				this.title = "请确定退款金额"
				this.real_money = item.refund_money
				this.type = 2
			},
			confirmReturn() { //确定拒绝退款
				if (this.type == 1) {
					if (this.error_reason == "") {
						httpRequest.toast("请输入拒绝申请的原因")
						return false
					}
					httpRequest.request('/api/shop.service_refund/refuse', 'POST', {
						order_refund_id: this.tkid,
						error_reason: this.error_reason
					}, false, false, true).then(res => {
						httpRequest.toast(res.msg);
						if (res.code == 1) {
							setTimeout(()=>{
								uni.navigateBack(1)
							},500)
						}
					}).catch(err => {
						httpRequest.toast(err.msg);
					})
					this.modalshow = false
					this.error_reason = ""
				} else {
					httpRequest.request('/api/shop.service_refund/agree', 'POST', {
						order_refund_id: this.tkid,
						real_money: this.real_money, //实际退款金额
					}, false, false, true).then(res => {
						httpRequest.toast(res.msg);
						if (res.code == 1) {
							setTimeout(()=>{
								uni.navigateBack(1)
							},500)
						}
					}).catch(err => {
						httpRequest.toast(err.msg);
					})
					this.modalshow = false
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.imgShop {
		width: 26.62rpx;
		height: 24rpx;
	}

	.imgBox {
		width: 80rpx;
		height: 80rpx;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 1rpx solid #F1F1F1;
		overflow: hidden;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.dan {
		width: 80vw;
		padding: 64rpx 40rpx 0rpx 40rpx;
	}

	.tuihuo {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
	}

	.money_tui {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #D48B39;
	}

	.order {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.hexiao {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
	}

	.white {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.erwie {
		width: 169rpx;
		height: 169rpx;
	}

	.code {
		padding: 30rpx 30rpx;
		margin-top: 30rpx;
		background-color: #fff;
	}

	::v-deep.u-safe-area-inset-bottom {
		padding-bottom: 0;
		padding-bottom: constant(safe-area-inset-bottom);
	}

	.fuzhi {
		padding: 0rpx 100rpx;
	}

	.copy {
		padding: 20rpx 40rpx;
		border-radius: 51rpx;
		background-color: rgba(212, 139, 57, 1);
		margin-top: 109rpx;
		color: #fff;
	}

	.dan {
		padding: 64rpx 40rpx 64rpx 40rpx;
	}

	.zhongtong {
		margin-top: 87rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
		padding: 34rpx 82rpx;
		border: 1rpx solid rgba(223, 223, 223, 1);
		border-radius: 10rpx;
	}

	.wuliu {
		font-size: 40rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.strongtext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.bigtext {
		font-size: 34rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #333333;
	}

	.xzqianshu {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: rgba(212, 139, 57, 1);
	}

	.huangsebtn {
		border: 2rpx solid rgba(243, 39, 28, 1);
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: rgba(243, 39, 28, 1);
	}

	.huisebtn {
		border: 2rpx solid #666666;
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.shuliang {
		font-size: 26rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #999999;
	}

	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.shilitu {
		width: 134rpx;
		height: 128rpx;
		border-radius: 14rpx;

		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}
	}

	.qianshu {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: rgba(243, 39, 28, 1);
	}

	.huisetext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.yhxiank {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.paddingbom {
		padding-bottom: 110rpx;
	}
</style>